package com.siysoft.tc.admin.service.Impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.siysoft.tc.admin.service.IAdminInterestService;
import com.siysoft.tc.base.bean.property.ResourceType;
import com.siysoft.tc.base.bean.to.Interest;
import com.siysoft.util.COMMON;
import com.siysoft.util.IMap;
import com.tc.base.dao.BaseDAO;

@Service
public class AdminInterestServiceImpl implements IAdminInterestService {
	@Autowired
	BaseDAO baseDao;

	@Override
	public List<Map<String, Object>> seekInterests(IMap iMap) throws Exception {
		// TODO Auto-generated method stub
		String hql = "SELECT db_interest.interest_id, db_interest.interest_name, "
				+ "db_resource.img_path FROM db_interest "
				+ "left Join db_resource ON db_resource.data_id = db_interest.interest_id "
				+ "and db_resource.data_type = '"+ ResourceType.INTEREST +"' ";
		if(COMMON.isEmpty(iMap.getInt("id")))
		{
			hql = "SELECT db_interest.interest_id, db_interest.interest_name, "
					+ "db_resource.img_path FROM db_interest "
					+ "left Join db_resource ON db_resource.data_id = db_interest.interest_id "
					+ "and db_resource.data_type = '"+ ResourceType.INTEREST +"' where db_interest.interest_id = " + iMap.getInt("id");
		}
		
		return (List<Map<String, Object>>) baseDao.findBySQLToMap(hql, null, -1, -1);
	}

	@Override
	public Integer addInterests(IMap iMap) {
		// TODO Auto-generated method stub
		Interest in = new Interest();
		in.setInterest_name(iMap.getString("name"));
		Integer id = (Integer) baseDao.saveReturnId(in);
		return id;
	}

	@Override
	public void delInterest(int int1) {
		// TODO Auto-generated method stub
		Interest it = (Interest)baseDao.findById(Interest.class, int1);
		baseDao.delete(it);
	}
	
	

}
